//
// Created by Tony on 2024/5/18.
//

#include "TokenQueue.h"

namespace Lexer {

shared_ptr<Token> TokenQueue::peek(size_t offet) {
    size_t pos = cursor + offet;
    if (pos >= tokens.size()) {
        return nullptr;
    }
    return tokens[pos];
}

shared_ptr<Token> TokenQueue::poll() {
    if (cursor >= tokens.size()) {
        return nullptr;
    }
    auto ret = tokens[cursor];
    lastPosition = ret->getPosition();
    tokens[cursor] = nullptr;
    cursor++;
    return ret;
}

void TokenQueue::append(const shared_ptr<TokenQueue>& other) {
    this->tokens.insert(tokens.end(), other->tokens.begin(), other->tokens.end());
}

} // namespace Lexer
